from flask_appbuilder import Model
from flask_appbuilder.models.mixins import AuditMixin
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship

"""

You can use the extra Flask-AppBuilder fields and Mixin's

AuditMixin will add automatic timestamp of created and modified by who


"""
class AppTarget(Model,AuditMixin):
    id = Column(Integer, primary_key=True)
    number = Column(String(20),comment="指标编号")
    title = Column(String(50),comment="指标名称")
    expression = Column(String(30),comment="指标公式")
    unit = Column(String(30),comment="单位")
    img = Column(String(100),comment="指标图标")
    frequency = Column(Integer,comment="频度")
    controlClass = Column(Integer, ForeignKey('app_controlclass.id'),comment="控制类型")
    computeClass = Column(Integer, ForeignKey('app_computeclass.id'),comment="计算类型")
    interface =  Column(Integer,comment="接口")
    app_controlclass = relationship('AppControlclass')
    app_computeclass = relationship('AppComputeclass')
    def __repr__(self):
        return self.title

class AppFrequency(Model):
    id = Column(Integer, primary_key=True)
    title = Column(String(50),comment="名称")
    def __repr__(self):
        return self.title

class AppControlclass(Model):
    id = Column(Integer, primary_key=True)
    title = Column(String(50),comment="名称")
    def __repr__(self):
        return self.title


class AppComputeclass(Model):
    id = Column(Integer, primary_key=True)
    title = Column(String(50),comment="名称")
    def __repr__(self):
        return self.title

